//
//  VideoViewCell.m
//  SnailPost
//
//  Created by Liuiu on 16/3/10.
//  Copyright © 2016年 抠泥ser. All rights reserved.
//

#import "VideoViewCell.h"
#import "PrefixHeader.pch"
#import "LiuiuCoreData.h"


@implementation VideoViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
//    self.isCollected = NO;
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView NightWithType:UIViewColorTypeNormal];
//        self.contentView.backgroundColor = [UIColor clearColor];
        
        self.xian =[[UIView alloc]init];
        _xian.backgroundColor =[UIColor gainsboroColor];
        [self.contentView addSubview:_xian];
        
        self.content = [[UILabel alloc]init];
        _content.textColor =[UIColor lightGrayColor];
        _content.font = [UIFont systemFontOfSize:15];
        [_content NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_content];
  
        self.image =[[UIImageView alloc]init];
        [self.contentView addSubview:_image];
        
        self.title = [[UILabel alloc]init];
        _title.backgroundColor =[UIColor redColor];
        _title.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [_title NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_title];
        
        
       
        self.content = [[UILabel alloc]init];
        _content.textColor =[UIColor lightGrayColor];
        _content.font = [UIFont systemFontOfSize:15];
        [_content NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_content];
        
        
        self.bofang = [[UIImageView alloc]init];
        _bofang.image = [UIImage imageNamed:@"bofang"];
      
        [_image addSubview:_bofang];
        
        
        self.time = [[UIImageView alloc]init];
        _time.image = [UIImage imageNamed:@"time"];
        [_time NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_time];
        
        
        self.times = [[UILabel alloc]init];
        _times.font = [UIFont systemFontOfSize:14];
        _times.textColor = [UIColor lightGrayColor];
        [_times NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_times];
        
        
        self.count = [[UIImageView alloc]init];
        _count.image =[UIImage imageNamed:@"bofang3"];
        [self.contentView addSubview:_count];
        
        
        self.counts =[[UILabel alloc]init];
        _counts.textColor = [UIColor lightGrayColor];
        _counts.font = [UIFont systemFontOfSize:14];
        [_counts NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_counts];
        
        
        self.share = [UIButton buttonWithType:UIButtonTypeCustom];

        [_share setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
        [_share addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_share];
       // [self.contentView addSubview:_share];
        
        
        self.shoucang = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shoucang setImage:[UIImage imageNamed:@"shoucang1"] forState:UIControlStateNormal];
        [_shoucang addTarget:self action:@selector(Inupate:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_shoucang];
        
        
        
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [_xian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(0, 0, 300, 0));
    }];
    [_bofang mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.image);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).width.insets(UIEdgeInsetsMake(10, 10, 265, 0));
    }];
    [_content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).width.insets(UIEdgeInsetsMake(45, 10, 230, 0));
    }];
    [_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(75, 10, 55, 10));
    }];
    
    
    
    [_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(270, 10, 15, self.contentView.frame.size.width - 35));
    }];
    [_times mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(270, 40, 15, self.contentView.frame.size.width - 100));
    }];
    [_count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(270, 100, 15, self.contentView.frame.size.width - 125));
    }];
    [_counts mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(270, 130, 15, self.contentView.frame.size.width - 190));
    }];
    [_share mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(272.5, 332.5, 17.5, 17.5));
    }];
    
    [_shoucang mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(265, 280, 15, 65));
    }];
    
    

    
}
- (void)Inupate:(UIButton *)btn
{
//****** 封装调用方法
    if ([[LiuiuCoreData defaultsCoreDataManager] selectModelWithKey:@"title" value:_hm.title])  {

        //提示已收藏成功
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"已经收藏~" message:@"快去看看吧!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alert show];
   
    }
   else if (![[LiuiuCoreData defaultsCoreDataManager]selectModelWithKey:@"title" value:_hm.title]) {
          [[LiuiuCoreData defaultsCoreDataManager] addWithModelTitle:_hm.title cover:_hm.cover length:_hm.length playCount:_hm.playCount mp4_url:_hm.mp4_url];
        //提示收藏成功
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"收藏成功~" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alert show];

    }
    [[LiuiuCoreData defaultsCoreDataManager]nslogCoreDataPath];
    

    [[LiuiuCoreData defaultsCoreDataManager]saveContext];
    

}

- (void)Click:(UIButton *)btn
{
    
    NSLog(@"fenxiangya ");
}

@end
